package com.dcloud.manage.dblib.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dcloud.manage.dblib.entity.request.QueryTableActReq;
import com.dcloud.manage.dblib.entity.vo.DatalibLogicActVO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import com.dcloud.manage.dblib.entity.DatalibLogicAct;
import com.dcloud.manage.dblib.service.IDatalibLogicActService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: datalib_logic_act
 * @Author: jeecg-boot
 * @Date:   2024-03-11
 * @Version: V1.0
 */
@Api(tags="datalib_logic_act")
@RestController
@RequestMapping("/api/datalibLogicAct/v1/")
@Slf4j
public class DatalibLogicActController extends JeecgController<DatalibLogicAct, IDatalibLogicActService> {
	@Autowired
	private IDatalibLogicActService datalibLogicActService;
	
	/**
	 * 根据表id查询逻辑表字段映射
	 *
	 * @param tableId
	 * @return
	 */
	@AutoLog(value = "根据表id查询逻辑表字段映射")
	@ApiOperation(value="根据表id查询逻辑表字段映射", notes="根据表id查询逻辑表字段映射")
	@GetMapping(value = "/getListByTableId")
	public Result<?> getListByTableId(@RequestParam(name="tableId") String tableId) {
		List<DatalibLogicActVO> list = datalibLogicActService.getListByTableId(tableId);
		return Result.OK(list);
	}

	/**
	 *   添加
	 *
	 * @param datalibLogicAct
	 * @return
	 */
	@AutoLog(value = "datalib_logic_act-添加")
	@ApiOperation(value="datalib_logic_act-添加", notes="datalib_logic_act-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody DatalibLogicAct datalibLogicAct) {
		datalibLogicActService.save(datalibLogicAct);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param datalibLogicAct
	 * @return
	 */
	@AutoLog(value = "datalib_logic_act-编辑")
	@ApiOperation(value="datalib_logic_act-编辑", notes="datalib_logic_act-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody DatalibLogicAct datalibLogicAct) {
		datalibLogicActService.updateById(datalibLogicAct);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "datalib_logic_act-通过id删除")
	@ApiOperation(value="datalib_logic_act-通过id删除", notes="datalib_logic_act-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		datalibLogicActService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "datalib_logic_act-批量删除")
	@ApiOperation(value="datalib_logic_act-批量删除", notes="datalib_logic_act-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.datalibLogicActService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "datalib_logic_act-通过id查询")
	@ApiOperation(value="datalib_logic_act-通过id查询", notes="datalib_logic_act-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		DatalibLogicAct datalibLogicAct = datalibLogicActService.getById(id);
		if(datalibLogicAct==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(datalibLogicAct);
	}


	 /**
	  * 根据表id以及其他信息查询字段映射
	  *
	  * @param queryTableActReq
	  * @return
	  */
	 @AutoLog(value = "根据表id以及其他信息查询字段映射")
	 @ApiOperation(value="根据表id以及其他信息查询字段映射", notes="根据表id以及其他信息查询字段映射")
	 @PostMapping(value = "/queryListByReq")
	 public Result<?> queryListByReq(@RequestBody QueryTableActReq queryTableActReq) {
		 List<DatalibLogicActVO> datalibLogicAct = datalibLogicActService.queryListByReq(queryTableActReq);
		 return Result.OK(datalibLogicAct);
	 }

}
